home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 February / OpenLinux 2.3 CD.iso / live / usr / include / st.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-10  |  8.9 KB  |  325 lines

  1. /*
  2.  * July 5, 1991
  3.  * Copyright 1991 Lance Norskog And Sundry Contributors
  4.  * This source code is freely redistributable and may be used for
  5.  * any purpose.  This copyright notice must be maintained. 
  6.  * Lance Norskog And Sundry Contributors are not responsible for 
  7.  * the consequences of using this software.
  8.  */
  9.  
  10. #ifdef VAXC
  11. #define IMPORT  globalref
  12. #define EXPORT  globaldef
  13. /*
  14.  * use the VAX C optimized functions 
  15.  */ 
  16. #define calloc  VAXC$CALLOC_OPT
  17. #define cfree   VAXC$CFREE_OPT
  18. #define free    VAXC$FREE_OPT
  19. #define malloc  VAXC$MALLOC_OPT
  20. #define realloc VAXC$REALLOC_OPT
  21. #else
  22. #define IMPORT  extern
  23. #define EXPORT 
  24. #endif
  25.  
  26.  
  27. /*
  28.  * Sound Tools sources header file.
  29.  */
  30.  
  31. #include <stdio.h>
  32.  
  33. #ifdef __alpha__
  34. #include <sys/types.h>   /* To get defines for 32-bit integers */
  35. #define    LONG    int32_t
  36. #define ULONG    u_int32_t
  37. #else
  38. #define    LONG    long
  39. #define ULONG    unsigned long
  40. #endif
  41.  
  42. #ifdef AMIGA
  43. #include "amiga.h"
  44. #endif /* AMIGA */
  45.  
  46. /*
  47.  * Handler structure for each format.
  48.  */
  49.  
  50. typedef struct format {
  51.     char    **names;    /* file type names */
  52.     int    flags;        /* details about file type */
  53.     void    (*startread)();            
  54.     LONG    (*read)();            
  55.     void    (*stopread)();        
  56.     void    (*startwrite)();            
  57.     void    (*write)();
  58.     void    (*stopwrite)();        
  59. } format_t;
  60.  
  61. IMPORT format_t formats[];
  62.  
  63. /* Signal parameters */
  64.  
  65. struct  signalinfo {
  66.     LONG        rate;        /* sampling rate */
  67.     int        size;        /* word length of data */
  68.     int        style;        /* format of sample numbers */
  69.     int        channels;    /* number of sound channels */
  70. };
  71.  
  72. /* Loop parameters */
  73.  
  74. struct  loopinfo {
  75.     int        start;        /* first sample */
  76.     int        length;        /* length */
  77.     int        count;        /* number of repeats, 0=forever */
  78.     int        type;        /* 0=no, 1=forward, 2=forward/back */
  79. };
  80.  
  81. /* Instrument parameters */
  82.  
  83. /* vague attempt at generic information for sampler-specific info */
  84.  
  85. struct  instrinfo {
  86.     char         MIDInote;    /* for unity pitch playback */
  87.     char        MIDIlow, MIDIhi;/* MIDI pitch-bend range */
  88.     char        loopmode;    /* semantics of loop data */
  89.     char        nloops;        /* number of active loops */
  90.     unsigned char    smpte[4];    /* SMPTE offset (hour:min:sec:frame) */
  91.                     /* this is a film audio thing */
  92. };
  93.  
  94.  
  95. #define MIDI_UNITY 60        /* MIDI note number to play sample at unity */
  96.  
  97. /* Loop modes, upper 4 bits mask the loop blass, lower 4 bits describe */
  98. /* the loop behaviour, ie. single shot, bidirectional etc. */
  99. #define LOOP_NONE          0    
  100. #define LOOP_8             32    /* 8 loops: don't know ?? */
  101. #define LOOP_SUSTAIN_DECAY 64    /* AIFF style: one sustain & one decay loop */
  102.  
  103. /* Pipe parameters */
  104.  
  105. struct    pipeinfo {
  106.     FILE    *pout;            /* Output file */
  107.     FILE    *pin;            /* Input file */
  108. };
  109.  
  110. /*
  111.  *  Format information for input and output files.
  112.  */
  113.  
  114. #define    PRIVSIZE    330
  115.  
  116. #define NLOOPS        8
  117.  
  118. struct soundstream {
  119.     struct    signalinfo info;    /* signal specifications */
  120.     struct  instrinfo instr;    /* instrument specification */
  121.     struct  loopinfo loops[NLOOPS];    /* Looping specification */
  122.     char    swap;            /* do byte- or word-swap */
  123.     char    seekable;        /* can seek on this file */
  124.     char    *filename;        /* file name */
  125.     char    *filetype;        /* type of file */
  126.     char    *comment;        /* comment string */
  127.     FILE    *fp;            /* File stream pointer */
  128.     format_t *h;            /* format struct for this file */
  129.     double    priv[PRIVSIZE/8];    /* format's private data area */
  130. };
  131.  
  132. IMPORT struct soundstream informat, outformat;
  133. typedef struct soundstream *ft_t;
  134.  
  135. /* flags field */
  136. #define FILE_STEREO    1    /* does file format support stereo? */
  137. #define FILE_LOOPS    2    /* does file format support loops? */
  138. #define FILE_INSTR    4    /* does file format support instrument specificications? */
  139.  
  140. /* Size field */
  141. #define    BYTE    1
  142. #define    WORD    2
  143. #define    DWORD    4
  144. #define    FLOAT    5
  145. #define DOUBLE    6
  146. #define IEEE    7        /* IEEE 80-bit floats.  Is it necessary? */
  147.  
  148. /* Style field */
  149. #define UNSIGNED    1    /* unsigned linear: Sound Blaster */
  150. #define SIGN2        2    /* signed linear 2's comp: Mac */
  151. #define    ULAW        3    /* U-law signed logs: US telephony, SPARC */
  152. #define ALAW        4    /* A-law signed logs: non-US telephony */
  153. #define ADPCM        5    /* Compressed PCM */
  154. #define GSM        6    /* GSM 6.10 33-byte frame lossy compression */
  155.  
  156. IMPORT char *sizes[], *styles[];
  157.  
  158. /*
  159.  * Handler structure for each effect.
  160.  */
  161.  
  162. typedef struct {
  163.     char    *name;            /* effect name */
  164.     int    flags;            /* this and that */
  165.     void    (*getopts)();        /* process arguments */
  166.     void    (*start)();        /* start off effect */
  167.     void    (*flow)();        /* do a buffer */
  168.     void    (*drain)();        /* drain out at end */
  169.     void    (*stop)();        /* finish up effect */
  170. } effect_t;
  171.  
  172. IMPORT effect_t effects[];
  173.  
  174. #define    EFF_CHAN    1        /* Effect can mix channels up/down */
  175. #define EFF_RATE    2        /* Effect can alter data rate */
  176. #define EFF_MCHAN    4        /* Effect can handle multi-channel */
  177. #define EFF_REPORT    8        /* Effect does nothing */
  178.  
  179. struct effect {
  180.     char        *name;        /* effect name */
  181.     struct signalinfo ininfo;    /* input signal specifications */
  182.     struct loopinfo   loops[8];    /* input loops  specifications */
  183.     struct instrinfo  instr;    /* input instrument  specifications */
  184.     struct signalinfo outinfo;    /* output signal specifications */
  185.     effect_t     *h;        /* effects driver */
  186.     LONG        *obuf;        /* output buffer */
  187.     LONG        odone, olen;    /* consumed, total length */
  188.     double        priv[PRIVSIZE];    /* private area for effect */
  189. };
  190.  
  191. typedef struct effect *eff_t;
  192.  
  193. #if    defined(__STDC__) || defined(ARM)
  194. #define    P1(a) a
  195. #define    P2(a,b) a, b
  196. #define    P3(a,b,c) a, b, c
  197. #define    P4(a,b,c,d) a, b, c, d
  198. #define    P5(a,b,c,d,e) a, b, c, d, e
  199. #define    P6(a,b,c,d,e,f) a, b, c, d, e, f
  200. #define    P7(a,b,c,d,e,f,g) a, b, c, d, e, f, g
  201. #define    P8(a,b,c,d,e,f,g,h) a, b, c, d, e, f, g, h
  202. #define    P9(a,b,c,d,e,f,g,h,i) a, b, c, d, e, f, g, h, i
  203. #define    P10(a,b,c,d,e,f,g,h,i,j) a, b, c, d, e, f, g, h, i, j
  204. #else
  205. #define    P1(a)
  206. #define    P2(a,b)
  207. #define    P3(a,b,c)
  208. #define    P4(a,b,c,d)
  209. #define    P5(a,b,c,d,e)
  210. #define    P6(a,b,c,d,e,f)
  211. #define    P7(a,b,c,d,e,f,g)
  212. #define    P8(a,b,c,d,e,f,g,h)
  213. #define    P9(a,b,c,d,e,f,g,h,i)
  214. #define    P10(a,b,c,d,e,f,g,h,i,j)
  215. #endif
  216.  
  217. /* Utilities to read and write shorts and longs little-endian and big-endian */
  218. unsigned short rlshort(P1(ft_t ft));            /* short little-end */
  219. unsigned short rbshort(P1(ft_t ft));            /* short big-end    */
  220. unsigned short wlshort(P2(ft_t ft, unsigned short us));    /* short little-end */
  221. unsigned short wbshort(P2(ft_t ft, unsigned short us));    /* short big-end    */
  222. ULONG rllong(P1(ft_t ft));            /* long little-end  */
  223. ULONG rblong(P1(ft_t ft));            /* long big-end     */
  224. ULONG wllong(P2(ft_t ft, ULONG ul));        /* long little-end  */
  225. ULONG wblong(P2(ft_t ft, ULONG ul));        /* long big-end     */
  226. /* Read and write words and longs in "machine format".  Swap if indicated.  */
  227. unsigned short rshort(P1(ft_t ft));            
  228. unsigned short wshort(P2(ft_t ft, unsigned short us));
  229. ULONG rlong(P1(ft_t ft));        
  230. ULONG wlong(P2(ft_t ft, ULONG ul));
  231. float          rfloat(P1(ft_t ft));
  232. void           wfloat(P2(ft_t ft, double f));
  233. double         rdouble(P1(ft_t ft));
  234. void           wdouble(P2(ft_t ft, double d));
  235.  
  236. /* Utilities to byte-swap values */
  237. unsigned short swapw(P1(unsigned short us));        /* Swap short */
  238. ULONG             swapl(P1(ULONG ul));            /* Swap long */
  239. float             swapf(P1(float f));            /* Swap float */
  240. double            swapd(P1(double d));            /* Swap double */
  241.  
  242. #ifdef ARM
  243. IMPORT double sfloor(P1(double x));   /* Hack our way around the flawed */
  244. IMPORT double sceil(P1(double x));    /* UnixLib floor ceil functions */
  245. #endif
  246.  
  247. IMPORT void report(P2(char *, ...)),  warn(P2(char *, ...)),
  248.      fail(P2(char *, ...));
  249.  
  250. /* util.c */
  251. IMPORT void geteffect(P1(eff_t));
  252. IMPORT void gettype(P1(ft_t));
  253. IMPORT void checkformat(P1(ft_t));
  254. IMPORT void copyformat(P2(ft_t, ft_t));
  255. IMPORT void cmpformats(P2(ft_t, ft_t));
  256.  
  257. typedef    unsigned int u_i;
  258. typedef    ULONG u_l;
  259. typedef    unsigned short u_s;
  260.  
  261. IMPORT float volume;    /* expansion coefficient */
  262. IMPORT int dovolume;
  263.  
  264. IMPORT float amplitude;    /* Largest sample so far */
  265.  
  266. IMPORT int writing;    /* are we writing to a file? */
  267.  
  268. /* export flags */
  269. IMPORT int verbose;    /* be noisy on stderr */
  270. IMPORT int summary;    /* just print summary of information */
  271.  
  272. IMPORT char *myname;
  273.  
  274. IMPORT int soxpreview;    /* Preview mode: be fast and ugly */
  275.  
  276. #define    MAXRATE    50L * 1024            /* maximum sample rate */
  277.  
  278. #if  defined(unix) || defined (__OS2__)
  279. /* Some wacky processors don't have arithmetic down shift, so do divs */
  280. /* Most compilers will turn this into a shift if they can, don't worry */
  281. #define RIGHT(datum, bits)    ((datum) / (1L << bits)) 
  282. #define LEFT(datum, bits)    ((datum) << bits) 
  283. #else
  284. /* x86 & 68k PC's have arith shift ops and dumb compilers */
  285. #define RIGHT(datum, bits)    ((datum) >> bits)
  286. #define LEFT(datum, bits)    ((datum) << bits)
  287. #endif
  288.  
  289. #ifndef    M_PI
  290. #define M_PI    3.14159265358979323846
  291. #endif
  292.  
  293. #if    defined(unix) || defined(AMIGA) || defined (__OS2__) \
  294.     || defined(OS9) || defined(ARM)
  295. #define READBINARY    "r"
  296. #define WRITEBINARY    "w"
  297. #endif
  298. #ifdef    VMS
  299. #define READBINARY      "r", "mbf=16", "ctx=stm" 
  300. #define WRITEBINARY     "w", "ctx=stm"
  301. #endif
  302. #ifdef    DOS
  303. #define READBINARY    "rb"
  304. #define WRITEBINARY    "wb"
  305. #endif
  306.  
  307. /* Error code reporting */
  308. #ifdef    QNX
  309. #include <errno.h>
  310. #endif
  311.  
  312. #if defined(unix) || defined(__OS2__)
  313. #include <errno.h>
  314. #endif
  315.  
  316. #ifdef    __OS2__
  317. #define REMOVE remove
  318. #else
  319. #define REMOVE unlink
  320. #endif
  321.  
  322. char *version();            /* return version number */
  323. /* ummmm??? */
  324.  
  325.